package com.example.HTML5DEMO;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ProgressBar;

public class MyActivity extends Activity {
	private WebView webView;
	private String url = "http://www.baidu.com";
	private ProgressBar pb;

	/**
	 * Called when the activity is first created.
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		findView();
		setData();
		setListener();
	}

	private void findView() {
		webView = (WebView) findViewById(R.id.webview);
		pb= (ProgressBar) findViewById(R.id.pb);
	}

	private void setData() {
//        this.getActionBar().
		WebSettings webSettings = webView.getSettings();
		webSettings.setJavaScriptEnabled(true);
		webView.getSettings().setSupportZoom(true);
		webView.getSettings().setBuiltInZoomControls(true);
		// file:///android_asset/
		webView.setWebViewClient(new android.webkit.WebViewClient() {
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return true;
			}

		});
		webView.setWebChromeClient(new WebViewClient());
		webView.loadUrl(url);
	}

	private void setListener() {

	}
	private class WebViewClient extends WebChromeClient {
		@Override
		public void onProgressChanged(WebView view, int newProgress) {
			pb.setProgress(newProgress);
			if(newProgress==100){
				pb.setVisibility(View.GONE);
			}
			super.onProgressChanged(view, newProgress);
		}


	}
}
